|
|
Component
BDLC
BDLC serial communication
Component Level: High
Category:
CPU Internal Peripherals-Communication
Typical Usage:
(Examples of a typical usage of the component in user code.
For more information please
see the page Component Code
Typical Usage.)
Assume the component name "BDLC1". (1) The first typical usage of this component is communication using communication events. Required component settings:
EVENTS.C
void BDLC1_OnReceiveData(void)
{
byte Out[5];
word Size=5;
word Len;
BDLC1_RecvBlock(Out,Size,&Len); //Read received data
BDLC1_ClearRxBuf(); //Clear Rx buffer
BDLC1_SendBlock(Out,Len); //Send the data back
}
void BDLC1_OnTransmitData(void)
{
BDLC1_ClearRxBuf(); //Data transmitted, Clear Rx buffer
}
(2)The second typical usage of this component is communication using transmission with multiple bytes IFR (In-Frame Response). The following example shows how to recognize a communication error using the method GetError. Note: In interrupt communication mode you can use the OnError event to recognize an error during communication. Required component settings:
MAIN.C
byte Flag;
BDLC1_TError error; //TError union is defined in the header file
byte Out[5];
byte ifr[3];
void main(void)
{
byte Len
.
.
.
Flag = 0; //Clear end of frame flag
BDLC1_SendBlock(Out,5); //Send data
while(!Flag) ; //Wait for Tx complete
BDLC1_GetError(&error); //Get errors
if(error.err == 0)
//No error
BDLC1_RecvIFR(ifr,3,&Len); //if no error, read IFR
else
if(err.errName.Arbitration)
//Arbitration error
else if(err.errName.Framing)
//Framing error
.
.
.
BDLC1_ClearRxBuf();
BDLC1_ClearIFRbuf();
.
.
.
}
EVENTS.C
extern byte TxFlag;
void BDLC1_OnTransmitData(void)
{
Flag |= 1; //Indicate end of frame
}
void BDLC1_OnReceiveData(void)
{
Flag |= 2; //Indicate end of frame
}
|